//
//  SAWechatAuthorizationVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/9/3.
//

#import "SAWechatAuthorizationVC.h"

@interface SAWechatAuthorizationVC ()

@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation SAWechatAuthorizationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - event
-(void)clickedSaveBtn {
    [self loadImageFinished:self.imageV.image];
}

- (void)loadImageFinished:(UIImage *)image
{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
}
 
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error == nil) {
        [Prompt popPromptViewWithMsg:@"图片已保存到相册" duration:3];
    }else {
        [Prompt popPromptViewWithMsg:@"图片保存失败" duration:3];
    }
//    NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);
}

#pragma mark - initUI
-(void)initUI {
    [self setNavigationItemBackBBIAndTitle:@"微信审核"];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight), kScreenWidth, kScaleNum(400))];
    [imageV sd_setImageWithURL:[NSURL URLWithString:@"http://images.kuaikuaifu.net/images/wxMerchantRegister.jpg"]];
    imageV.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imageV];
    self.imageV = imageV;
    
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight + 400), kScreenWidth, kScaleNum(109))];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    UIButton *wechatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [wechatBtn setImage:[UIImage imageNamed:@"authorization_wechat_2"] forState:UIControlStateNormal];
    wechatBtn.frame = CGRectMake(0, kScaleNum(StatusHeight + 410), kScreenWidth, kScaleNum(19));
    [wechatBtn setTitle:@" 微信支付" forState:UIControlStateNormal];
    [wechatBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    wechatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    wechatBtn.titleLabel.font = kFont(14);
    wechatBtn.userInteractionEnabled = NO;
    [self.view addSubview:wechatBtn];
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [saveBtn setBackgroundImage:[UIImage imageNamed:@"button_bg_green"] forState:UIControlStateNormal];
    saveBtn.frame = CGRectMake(kScaleNum(70), kScaleNum(StatusHeight + 459), kScaleNum(235), kScaleNum(35));
    [saveBtn setTitle:@"保存二维码" forState:UIControlStateNormal];
    saveBtn.titleLabel.font = kFont(16);
    [saveBtn addTarget:self action:@selector(clickedSaveBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:saveBtn];
    
    UILabel *tipLab = [[UILabel alloc] initWithFrame:CGRectMake(kScaleNum(67), kScaleNum(StatusHeight + 535), kScaleNum(300), kScaleNum(14))];
    tipLab.textColor = kBlackColor;
    tipLab.font = kFont(13);
    tipLab.text = @"授权方式:";
    tipLab.textAlignment = NSTextAlignmentLeft;
    [self.view  addSubview:tipLab];
    
    UILabel *tipLab2 = [[UILabel alloc] initWithFrame:CGRectMake(kScaleNum(67), kScaleNum(StatusHeight + 555), kScaleNum(300), kScaleNum(14))];
    tipLab2.textColor = kBlackColor;
    tipLab2.font = kFont(13);
    tipLab2.text = @"1、可用微信直接扫描上图二维码进入微信授权;";
    tipLab2.textAlignment = NSTextAlignmentLeft;
    [self.view  addSubview:tipLab2];
    
    UILabel *tipLab3 = [[UILabel alloc] initWithFrame:CGRectMake(kScaleNum(67), kScaleNum(StatusHeight + 575), kScaleNum(300), kScaleNum(14))];
    tipLab3.textColor = kBlackColor;
    tipLab3.font = kFont(13);
    tipLab3.text = @"2、保存授权二维码到相册,在微信里面识别授权;";
    tipLab3.textAlignment = NSTextAlignmentLeft;
    [self.view  addSubview:tipLab3];
}

@end
